package homework03.test03;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Test03 {

    public static void main(String[] args) {

        Map<Student, String> map = new HashMap<>();

        map.put(new Student("刘备", 40), "河北涿州人");
        map.put(new Student("关羽", 35), "河东解良人");
        map.put(new Student("张飞", 30), "幽州涿郡人");

        //第一种方式:
        Set<Student> students = map.keySet();
        for (Student student:students) {
            System.out.println(student + ":" + map.get(student));
        }

        System.out.println("=======================================");

        //第二种方法
        Set<Map.Entry<Student, String>> entries = map.entrySet();
        for (Map.Entry<Student, String> entry:entries) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }

        System.out.println("=======================================");

        //第三种方法
        Iterator<Student> iterator = map.keySet().iterator();
        while (iterator.hasNext()) {
            Student student = iterator.next();
            System.out.println(student + ":" + map.get(student));
        }

        System.out.println("=======================================");
        //第四种方法
        Iterator<Map.Entry<Student, String>> iterator1 = map.entrySet().iterator();
        while (iterator1.hasNext()) {
            Map.Entry<Student, String> next = iterator1.next();
            System.out.println(next.getKey() + ":" + next.getValue());
        }

    }
}
